package com.cjlgb.design.gateway.cfgbean;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author WFT
 * @date 2019/5/25
 * description:
 */
@Configuration
public class TestConfiguration {

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        return builder.routes()
                .route(predicateSpec -> predicateSpec
                        .path("/get")
                        .filters(filter -> filter
                                .addRequestHeader("HelloWorld","Spring Cloud Gateway")
                        )
                        .uri("http://httpbin.org:80")
                )
                .route(predicateSpec -> predicateSpec
                        .host("*.hystrix.com")
                        .filters(gatewayFilterSpec -> gatewayFilterSpec
                                .hystrix(config -> config
                                        .setName("myCmd")
                                        .setFallbackUri("forward:/fallback")
                                )
                        )
                        .uri("http://httpbin.org:80")
                )
                .build();
    }

}
